package main

func addBinary(a string, b string) string {
	i := len(a) - 1
	j := len(b) - 1
	var result []byte
	var nextBit byte = 0
	for i >= 0 || j >= 0 || nextBit > 0 {
		var a0 byte = 0
		if i >= 0 {
			a0 = a[i] - '0'
			i--
		}
		var b0 byte = 0
		if j >= 0 {
			b0 = b[j] - '0'
			j--
		}
		c0 := a0 + b0 + nextBit
		if c0 >= 2 {
			c0 -= 2
			nextBit = 1
		} else {
			nextBit = 0
		}
		result = append(result, c0+'0')
	}
	reversed := make([]byte, len(result))
	for i, v := range result {
		reversed[len(result)-i-1] = v
	}
	return string(reversed)
}

func main() {
	println(addBinary("11", "1"))
	println(addBinary("1010", "1011"))
	println(addBinary("0", "0"))
	println(addBinary("0", "1"))
}
